function getCode(_this, num) {
  _this.setData({
    sendCode: true
  })
  var remain = num;  //用另外一个变量来操作秒数是为了保存最初定义的倒计时秒数，就不用在计时完之后再手动设置秒数
  var time = setInterval(function () {
    if (remain == 1) {
      clearInterval(time);
      _this.setData({
        sec: num,
        sendCode: false
      })
      return false      //必须有
    }
    remain--;
    _this.setData({
      sec: remain
    })
  }, 1000)
  //调用发送接口
  var sendVerifyRes = true;


  //根据接口返回结果弹出提示信息
  if (sendVerifyRes) {
    wx.showToast({
      title: '验证码发送成功！',
      icon: 'none',
      duration: 1500
    })
  } else {
    wx.showToast({
      title: '验证码发送失败！',
      icon: 'none',
      duration: 1500
    })
  }

}

function validateMobile(mobile) {
  if (mobile == undefined || mobile.length == 0) {
    wx.showToast({
      title: '请输入手机号',
      icon: 'none',
      duration: 1500
    })
    return false;
  }
  if (mobile.length != 11) {
    wx.showToast({
      title: '手机号长度有误',
      icon: 'none',
      duration: 1500
    })
    return false;
  }
  var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  if (!myreg.test(mobile)) {
    wx.showToast({
      title: '手机号有误',
      icon: 'none',
      duration: 1500
    })
    return false;
  }
  return true;
}

function validatePwds(pwd, rePwd) {

  if (pwd == undefined || pwd.length == 0) {
    wx.showToast({
      title: '请输入密码',
      icon: 'none',
      duration: 1500
    })
    return false;
  }

  if (pwd.length < 6) {
    wx.showToast({
      title: '密码长度不能小于6位',
      icon: 'none',
      duration: 1500
    })
    return false;
  }

  if (pwd === rePwd) {
    return true;
  } else {
    wx.showToast({
      title: '两次密码输入不一致',
      icon: 'none',
      duration: 1500
    })
    return false;
  }
}

function validateVerifyCode(code) {
  if (code == undefined || code.length == 0) {
    wx.showToast({
      title: '请输入验证码',
      icon: 'none',
      duration: 1500
    })
    return false;
  }
  return true;
}

exports.getCode = getCode;
exports.validateMobile = validateMobile;
exports.validatePwds = validatePwds;
exports.validateVerifyCode = validateVerifyCode;